import request from '@/utils/request'
import fs from 'fs'

//发布帖子
export function addArticleApi(articleForm,files){
    const formData = new FormData();
    files.forEach(file => {
        formData.append('images', file);
    });
    return request({
        method:'post',
        url:`/post/add`,
        params:{
            "user_id":articleForm.userId,
            "title":articleForm.title,
            "content":articleForm.content
        },
       data:formData
    })
}
//删除帖子
export function delArticleApi(postId){
    //posrId 帖子id
    return request({
        method:'delete',
        url:'/post/delete',
        params:{
            "postId":postId
        }
    })
}
//查找用户的分页帖子数据
export function getUserArticleListApi(page,userId){
    return request({
        method:'get',
        url:'/post/find',
        params:{
            "page":page,
            "userId":userId
        }
    })
}
//获取已经审核的分页帖子数据
export function getCheckedArticleListApi(page){
    return request({
        method:'get',
        url:'/post/find/all',
        data:page
    })
}

//获取最新
export function getNewArticleListApi(page){
    return request({
        method:'get',
        url:'/post/find/new',
        data:page
    })
}

//获取最热
export function getHotArticleListApi(page){
    return request({
        method:'get',
        url:'/post/find/hot',
        data:page
    })
}

//给帖子增加浏览量
export function addArticleWatchApi(postId){
    return request({
        method:'get',
        url:'/post/inc_view',
        params:{
            "postId":postId
        }
    })
}

//修改帖子
export function modyfyArticleApi(article){
    return request({
        method:'post',
        url:'/post/update',
        data:article
    })
}

//给帖子点赞
export function likeArticleApi(post_id,user_id){
    return request({
        method:'post',
        url:'/post/like',
        data:{
            "post_id":post_id,
            "user_id":user_id
        }
    })
}
//根据帖子id查找帖子
export function getArticleApi(postId){
    return request({
        method:'get',
        url:'/post/find/post',
        params:{
            "postId":postId
        }
    })
}